import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class LoveOrderManageService {

  private serviceUrls: any = {
    dictUrl: '/dict/detail', // 字典查询
    uploadFileUrl: '/common/upload/file', // 上传
    getModelListUrl: '/recycleModel/list', // 机型配置列表
    aircraftInspectorUrl: '/sys/user/findCheck', // 查询验机师
    verificationImeiUrl: '/recycleMachine/selectCount', // 回收imei验证

    orderListUrl: '/recycleOrder/list', // 订单列表
    orderDetailsUrl: '/recycleOrder/details', // 订单详情
    updatePayInfoUrl: '/recycleOrder/updatePayInfo', // 修改支付信息
    savePaymentUrl: '/recycleOrder/payOrder', // 打款成功 | 失败
    refundOrderUrl: '/recycleOrder/refundOrder', // 取消订单
    backOrSellUrl: '/recycleOrder/backOrSell', // 不卖了 | 立即收钱
    orderFollowUrl: '/recycleOrder/orderFollow', // 跟进
    recoveryOrderExportUrl: '/recycleOrder/findExcel', // 回收订单导出
    closeOrderUrl: '/recycleOrder/closeOrder', // 关闭订单

    refundOrderGoodsUrl: '/recycleOrder/regretRefund', // 反悔退货
    continueRecyclingUrl: '/recycleOrder/continueRecovery', // 继续回收

    pushReportDataUrl: '/phoneCheck/saveOrderCheck', // 推送验机报告
    updateReportUrl: '/phoneCheck/addOrUpdatePhone', // 添加 | 修改验机报告
    getReportDetailUrl: '/phoneCheck/details', // 验机报告详情
    addCheckInfoUrl: '/recycleOrder/addCheckInfo', // 机器验机详情--添加继续验机机器信息
    lockingWorkerUrl: '/phoneCheck/occupyOrder', // 验机师锁定订单
    locationListUrl: '/recycleLibrary/list', // 库位下拉
    updateReturnDataUrl: '/recycleOrder/setAddress', // 添加编辑退货信息
    deletePhoneCheckUrl: '/phoneCheck/delete', // 删除验机详情列表

    backSendMessageUrl: '/recycleOrder/sendSms', // 回收发送短信
    backEditDetailsUrl: '/recycleOrder/updatePCDetails' // 回收修改验机详情
  };

  constructor(public httpClient: HttpClient) { }

  // 查询库位lits
  getLocationList(params: any) {
    return this.httpClient.post(this.serviceUrls.locationListUrl, params).toPromise();
  }

  // 查询验机师
  getMasterWorkerList() {
    return this.httpClient.get(this.serviceUrls.aircraftInspectorUrl).toPromise();
  }

  // 锁定验机师订单
  lockingWorkerData(okey: any) {
    let params = {
      okey
    }
    return this.httpClient.get(this.serviceUrls.lockingWorkerUrl, { params }).toPromise();
  }

  // 查询机型配置列表(注：仅验机页面使用--新增)
  getModelList(name: any): Observable<any> {
    let params = {
      page: 1,
      pageSize: 999999,
      name
    }
    return this.httpClient.post(this.serviceUrls.getModelListUrl, params);
  }

  // 查询机型配置列表(注：仅验机页面使用--编辑查看)
  getEditModelList(objs: any) {
    let params = {
      page: 1,
      pageSize: 999999,
      ...objs
    }
    return this.httpClient.post(this.serviceUrls.getModelListUrl, params).toPromise();
  }

  // 查询订单列表
  getOrderList(params: any) {
    return this.httpClient.post(this.serviceUrls.orderListUrl, params).toPromise();
  }

  // 查询订单详情
  getOrderDetails(params: any) {
    return this.httpClient.get(this.serviceUrls.orderDetailsUrl, { params }).toPromise();
  }

  // 修改支付信息
  updatePayInfo(params: any) {
    return this.httpClient.post(this.serviceUrls.updatePayInfoUrl, params).toPromise();
  }

  // 打款成功 | 失败
  savePaymentData(params: any) {
    return this.httpClient.post(this.serviceUrls.savePaymentUrl, params).toPromise();
  }

  // 取消订单
  refundOrderData(params: any) {
    return this.httpClient.get(this.serviceUrls.refundOrderUrl, { params }).toPromise();
  }

  // 不卖了 | 立即收钱
  saveBackOrSellData(params: any) {
    return this.httpClient.post(this.serviceUrls.backOrSellUrl, params).toPromise();
  }

  // 推送验机报告
  pushReportData(params: any) {
    return this.httpClient.get(this.serviceUrls.pushReportDataUrl, { params }).toPromise();
  }

  // 新增 | 修改验机报告
  updateReportData(params: any) {
    return this.httpClient.post(this.serviceUrls.updateReportUrl, params).toPromise();
  }

  // 查看验机报告详情
  getReportDetail(params: any) {
    return this.httpClient.get(this.serviceUrls.getReportDetailUrl, { params }).toPromise();
  }

  // 机器验机详情--原因添加信息
  addCheckInfoData(params: any) {
    return this.httpClient.post(this.serviceUrls.addCheckInfoUrl, params).toPromise();
  }

  // 退货信息新增 | 编辑
  updateReturnInfoData(params: any) {
    return this.httpClient.post(this.serviceUrls.updateReturnDataUrl, params).toPromise();
  }

  // 删除验机详情Item
  deletePhoneCheckData(params: any) {
    return this.httpClient.get(this.serviceUrls.deletePhoneCheckUrl, { params }).toPromise();
  }

  // 跟进
  orderFollowUpData(params: any) {
    return this.httpClient.post(this.serviceUrls.orderFollowUrl, params).toPromise();
  }

  // 回收订单导出
  recoveryOrderExportData(params: any) {
    return this.httpClient.get(this.serviceUrls.recoveryOrderExportUrl, { params, responseType: 'blob' }).toPromise();
  }

  // 反悔退货
  refundOrderGoodsData(params: any) {
    return this.httpClient.post(this.serviceUrls.refundOrderGoodsUrl, params).toPromise();
  }

  // 继续回收
  continueRecyclingData(params: any) {
    return this.httpClient.post(this.serviceUrls.continueRecyclingUrl, params).toPromise();
  }

  // 回收关闭订单
  closeOrderData(params: any) {
    return this.httpClient.post(this.serviceUrls.closeOrderUrl, params).toPromise();
  }

  // 回收IMEI验证
  verificationImeiData(params: any) {
    return this.httpClient.post(this.serviceUrls.verificationImeiUrl, params).toPromise();
  }

  // 回收发送短信
  backSendMessageData(params: any) {
    return this.httpClient.post(this.serviceUrls.backSendMessageUrl, params).toPromise();
  }

  // 回收修改验机详情
  backEditDetailsData(params: any) {
    return this.httpClient.get(this.serviceUrls.backEditDetailsUrl, {params}).toPromise();
  }

  /**
   * 字典查询
   * @param parentKey 
   * @returns 
   */
  dictListData(parentKey: any) {
    let params: any = {
      parentKey: parentKey,
      pageNum: 0,
      pageSize: 0
    };
    return this.httpClient.get(this.serviceUrls.dictUrl, { params: params }).toPromise();
  }

  /**
   * 文件上传
   * @param fileToUpload 
   * @returns 
   */
  uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "love-recyc");
    return this.httpClient.post(this.serviceUrls.uploadFileUrl, formData).toPromise();
  }
}



